package great.project.common.http;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * @author Administrator
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Result<T> {

    private Integer code;

    private String msg;

    private T data;

    private Result() {
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Object getData() {
        return data;
    }

    public  static <T> Result<T> success(Integer code, String msg, T data) {
        Result<T> objectResult = new Result<>();
        objectResult.code = code;
        objectResult.msg = msg;
        objectResult.data = data;
        return objectResult;
    }


    public static <T> Result<T> success(String msg, T data) {
        return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
    }

    public static <T> Result<T> success(T data) {
        return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
    }

    public static <T> Result<T> success() {
        return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), null);
    }


    public static <T> Result<T> fail(Integer code, String msg, T data) {
        Result<T> objectResult = new Result<T>();
        objectResult.code = code;
        objectResult.msg = msg;
        objectResult.data = data;
        return objectResult;
    }


    public static <T> Result<T> fail(String msg, T data) {
        return success(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getMsg(), data);
    }

    public static <T> Result<T> fail(T data) {
        return success(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getMsg(), data);
    }
    public static <T> Result<T> fail(String msg) {
        return success(ResultEnum.FAIL.getCode(), msg, null);
    }

    public static <T> Result<T> fail() {
        return success(ResultEnum.FAIL.getCode(), ResultEnum.FAIL.getMsg(), null);
    }


}
